package cn.iwit.util;

public class TokenUtils {
    public static String AES_KEY = "2704FB67";

    /**
     * 生成token
     *
     * @param value
     * @return
     * @throws Exception
     */
    public static String getToken(String value) throws Exception {
        String token = EncryptUtils.encryptToDES(AES_KEY, value);
        token = EncryptUtils.encryptToDES(AES_KEY, token + "_" + AES_KEY);
        return token;
    }

    /**
     * @param token
     * @return
     * @throws Exception
     */
    public static boolean checkToken(String token) throws Exception {
        String value = EncryptUtils.decryptByDES(AES_KEY, token);
        //value = EncryptUtils.decryptByDES(AES_KEY, value);
        String[] arr = value.split("_");
        if (arr.length > 1 && arr[1].equals(AES_KEY)) {
            return true;
        }
        return false;
    }



}
